package thread;

import cn.hutool.core.date.StopWatch;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author: 582895699@qq.com
 * @Desctription: CountDownLatch
 * @Date: Created in 2021/12/13 16:12
 */
@Slf4j
public class CountDownLatchTest {

    public static void main(String[] args) throws InterruptedException, ExecutionException {
        CountDownLatch countDownLatch = new CountDownLatch(1000);

        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        ExecutorService executorService = Executors.newCachedThreadPool();
        for (int i = 0; i < 1000; i++) {
            executorService.execute(new TestCallAbleClass(countDownLatch));
        }
        countDownLatch.await();
        stopWatch.stop();
        log.info("stopWatch:{}", stopWatch.prettyPrint());
    }
}
